﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Input;

namespace DXJoystickSupport
{
    public class DXJoyButtons
    {
        #region Fields
        private readonly Dictionary<DXJoyButton, ButtonState> buttons;
        private object lockButtons;
        #endregion

        #region Properties
        public ButtonState Button01
        {
            get { return buttons[DXJoyButton.Button01]; }
        }
        public ButtonState Button02
        {
            get { return buttons[DXJoyButton.Button02]; }
        }
        public ButtonState Button03
        {
            get { return buttons[DXJoyButton.Button03]; }
        }
        public ButtonState Button04
        {
            get { return buttons[DXJoyButton.Button04]; }
        }
        public ButtonState Button05
        {
            get { return buttons[DXJoyButton.Button05]; }
        }
        public ButtonState Button06
        {
            get { return buttons[DXJoyButton.Button06]; }
        }
        public ButtonState Button07
        {
            get { return buttons[DXJoyButton.Button07]; }
        }
        public ButtonState Button08
        {
            get { return buttons[DXJoyButton.Button08]; }
        }
        public ButtonState Button09
        {
            get { return buttons[DXJoyButton.Button09]; }
        }
        public ButtonState Button10
        {
            get { return buttons[DXJoyButton.Button10]; }
        }
        public ButtonState Button11
        {
            get { return buttons[DXJoyButton.Button11]; }
        }
        public ButtonState Button12
        {
            get { return buttons[DXJoyButton.Button12]; }
        }
        public ButtonState NegativeXAxis
        {
            get { return buttons[DXJoyButton.NegativeXAxis]; }
        }
        public ButtonState PositiveXAxis
        {
            get { return buttons[DXJoyButton.PositiveXAxis]; }
        }
        public ButtonState NegativeYAxis
        {
            get { return buttons[DXJoyButton.NegativeYAxis]; }
        }
        public ButtonState PositiveYAxis
        {
            get { return buttons[DXJoyButton.PositiveYAxis]; }
        }
        public ButtonState NegativeZAxis
        {
            get { return buttons[DXJoyButton.NegativeZAxis]; }
        }
        public ButtonState PositiveZAxis
        {
            get { return buttons[DXJoyButton.PositiveZAxis]; }
        }
        public ButtonState NegativerZAxis
        {
            get { return buttons[DXJoyButton.NegativerZAxis]; }
        }
        public ButtonState PositiverZAxis
        {
            get { return buttons[DXJoyButton.PositiverZAxis]; }
        }
        public ButtonState PointOfViewN
        {
            get { return buttons[DXJoyButton.PointOfViewN]; }
        }
        public ButtonState PointOfViewNE
        {
            get { return buttons[DXJoyButton.PointOfViewNE]; }
        }
        public ButtonState PointOfViewE
        {
            get { return buttons[DXJoyButton.PointOfViewE]; }
        }
        public ButtonState PointOfViewSE
        {
            get { return buttons[DXJoyButton.PointOfViewSE]; }
        }
        public ButtonState PointOfViewS
        {
            get { return buttons[DXJoyButton.PointOfViewS]; }
        }
        public ButtonState PointOfViewSW
        {
            get { return buttons[DXJoyButton.PointOfViewSW]; }
        }
        public ButtonState PointOfViewW
        {
            get { return buttons[DXJoyButton.PointOfViewW]; }
        }
        public ButtonState PointOfViewNW
        {
            get { return buttons[DXJoyButton.PointOfViewNW]; }
        }
        #endregion

        public DXJoyButtons()
        {
            lockButtons = new object();
            this.buttons = new Dictionary<DXJoyButton, ButtonState>();
            this.buttons.Add(DXJoyButton.Button01, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button02, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button03, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button04, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button05, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button06, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button07, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button08, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button09, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button10, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button11, ButtonState.Released);
            this.buttons.Add(DXJoyButton.Button12, ButtonState.Released);
            this.buttons.Add(DXJoyButton.NegativerZAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.NegativeXAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.NegativeYAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.NegativeZAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PositiverZAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PositiveXAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PositiveYAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PositiveZAxis, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewN, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewNE, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewE, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewSE, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewS, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewSW, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewW, ButtonState.Released);
            this.buttons.Add(DXJoyButton.PointOfViewNW, ButtonState.Released);
        }
        
        internal void Update(DXJoyButton button, ButtonState state)
        {
            lock (lockButtons)
            {
                this.buttons[button] = state;
            }
        }

        public ButtonState State(DXJoyButton button)
        {
            lock (lockButtons)
            {
                return this.buttons[button];
            }
        }
    }
}
